home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sources / xbiff / xbiff.c < prev    next >
C/C++ Source or Header  |  1994-09-27  |  4KB  |  113 lines

  1. /*
  2.  * $XConsortium: xbiff.c,v 1.17 91/01/10 14:25:32 gildea Exp $
  3.  *
  4.  * Copyright 1988 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * Author:  Jim Fulton, MIT X Consortium
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <X11/Xatom.h>
  21. #include <X11/Intrinsic.h>
  22. #include <X11/StringDefs.h>
  23. #include <X11/Xaw/Mailbox.h>
  24. #include <X11/Xaw/Cardinals.h>
  25.  
  26. extern void exit();
  27. static void quit();
  28.  
  29. char *ProgramName;
  30.  
  31. static XrmOptionDescRec options[] = {
  32. { "-update", "*mailbox.update", XrmoptionSepArg, (caddr_t) NULL },
  33. { "-file",   "*mailbox.file", XrmoptionSepArg, (caddr_t) NULL },
  34. { "-volume", "*mailbox.volume", XrmoptionSepArg, (caddr_t) NULL },
  35. { "-shape",  "*mailbox.shapeWindow", XrmoptionNoArg, (caddr_t) "on" },
  36. };
  37.  
  38. static XtActionsRec xbiff_actions[] = {
  39.     { "quit", quit },
  40. };
  41. static Atom wm_delete_window;
  42.  
  43. static void Usage ()
  44. {
  45.     static char *help_message[] = {
  46. "where options include:",
  47. "    -display host:dpy              X server to contact",
  48. "    -geometry geom                 size of mailbox",
  49. "    -file file                     file to watch",
  50. "    -update seconds                how often to check for mail",
  51. "    -volume percentage             how loud to ring the bell",
  52. "    -bg color                      background color",
  53. "    -fg color                      foreground color",
  54. "    -rv                            reverse video",
  55. "    -shape                         shape the window",
  56. NULL};
  57.     char **cpp;
  58.  
  59.     fprintf (stderr, "usage:  %s [-options ...]\n", ProgramName);
  60.     for (cpp = help_message; *cpp; cpp++) {
  61.     fprintf (stderr, "%s\n", *cpp);
  62.     }
  63.     fprintf (stderr, "\n");
  64.     exit (1);
  65. }
  66.  
  67.  
  68. void main (argc, argv)
  69.     int argc;
  70.     char **argv;
  71. {
  72.     XtAppContext xtcontext;
  73.     Widget toplevel, w;
  74.  
  75.     ProgramName = argv[0];
  76.  
  77.     toplevel = XtAppInitialize(&xtcontext, "XBiff", options, XtNumber (options),
  78.                    &argc, argv, NULL, NULL, 0);
  79.     if (argc != 1) Usage ();
  80.  
  81.     /*
  82.      * This is a hack so that f.delete will do something useful in this
  83.      * single-window application.
  84.      */
  85.     XtAppAddActions (xtcontext, xbiff_actions, XtNumber(xbiff_actions));
  86.     XtOverrideTranslations(toplevel,
  87.            XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
  88.  
  89.     w = XtCreateManagedWidget ("mailbox", mailboxWidgetClass, toplevel,
  90.                    NULL, 0);
  91.     XtRealizeWidget (toplevel);
  92.     wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
  93.                                     False);
  94.     (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
  95.                             &wm_delete_window, 1);
  96.     XtAppMainLoop (xtcontext);
  97. }
  98.  
  99. static void quit (w, event, params, num_params)
  100.     Widget w;
  101.     XEvent *event;
  102.     String *params;
  103.     Cardinal *num_params;
  104. {
  105.     if (event->type == ClientMessage &&
  106.         event->xclient.data.l[0] != wm_delete_window) {
  107.         XBell (XtDisplay(w), 0);
  108.         return;
  109.     }
  110.     XCloseDisplay (XtDisplay(w));
  111.     exit (0);
  112. }
  113.